// composables/usePageConfig.js
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { smartTranslate as $t } from '@/lang';
import defaultSettings from '@/settings';

export default function usePageConfig() {
  const route = useRoute();
  const { locale } = useI18n();

  // 自动同步路由标题
  watch(
    () => route.path,
    () => {
      const meta = route.meta || {};
      const pageTitle = $t(meta.key, meta.title);
      if (pageTitle) {
        document.title = pageTitle + ' - ' + defaultSettings.title;
      } else {
        document.title = defaultSettings.title;
      }
    },
    { immediate: true },
  );

  // 自动同步语言设置
  watch(locale, (newVal) => {
    document.documentElement.lang = newVal;
  });
}
